package com.promis.party.ui.partywork.organizeMag.relation;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.promis.party.R;
import com.promis.party.helper.ContextHelper;
import com.promis.party.ui.home.message.MessageDetailActivity;
import com.promis.widget.FragmentTabHost;
import com.promis.widget.paging.OnPageRefreshListener;
import com.promis.widget.paging.OnPageScrollListener;
import com.promis.widget.paging.PageRefreshRecyclerView;
import com.promis.widget.recycler.RecyclerLayoutManagerHelper;

public class RelationTransferFragment extends Fragment {

    private ContextHelper contextHelper;

    private LinearLayout rootLayout;
    private PageRefreshRecyclerView pageRefreshRecyclerView;
    private RecyclerView rylvContainer;
    private RelationTransferAdapter adaptMessage;

    public final static RelationTransferFragment newInstance() {
        RelationTransferFragment fragment = new RelationTransferFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootLayout = (LinearLayout) inflater.inflate(R.layout.fragment_item_list, null, false);
        pageRefreshRecyclerView = rootLayout.findViewById(R.id.fragment_item_prrv_container);
        initData();
        initListener();
        return rootLayout;
    }


    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
//        outState.putSerializable("receiptTradeList", receiptTradeList);
//        outState.putSerializable("pageInfo", pageInfo);
    }

    private void initData() {
        contextHelper = new ContextHelper(getContext());
        rylvContainer = pageRefreshRecyclerView.getRecyclerView();
        RecyclerLayoutManagerHelper.buildVerticalLinearLayoutManager(getContext(), rylvContainer);
        adaptMessage = new RelationTransferAdapter(getContext());
        rylvContainer.setAdapter(adaptMessage);

    }

    private void initListener() {
        adaptMessage.setOnItemClickListener(new RelationTransferAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                TabLayout tabHost = getActivity().findViewById(R.id.activity_chart_tbly_container);
                int p = tabHost.getSelectedTabPosition();
                Intent intent = null;
                if(p == 0){
                    intent = new Intent(getContext(), RelationTransferOutDetailActivity.class);
                }else{
                    intent = new Intent(getContext(), RelationTransferInDetailActivity.class);
                }
                startActivity(intent);
            }
        });

        pageRefreshRecyclerView.setOnPageScrollListener(new OnPageScrollListener() {
            @Override
            public void onLoadPageData() {
            }
        });
        pageRefreshRecyclerView.setOnRefreshListener(new OnPageRefreshListener() {
            @Override
            public void onRefresh() {
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}
